#include"RingQueue.hpp"
#include"Task.hpp"
void* ProdRunFunc(void* args)
{
    RingQueue<DataType>* loopQueue = static_cast<RingQueue<DataType>*>(args);
    while(true)
    {
        //生产数据
        int x = rand() % 10 +1;
        int y = x + 1;
        DataType data(x,y);
        loopQueue->Push(data);
        std::cout<<"生产者生产task-> "<<"add Task"<<std::endl;
    }
}
void* ConRunFunc(void* args)
{
    RingQueue<DataType>* loopQueue = static_cast<RingQueue<DataType>*>(args);
    while(true)
    {
        sleep(1);  
        //消费数据
        DataType data;
        loopQueue->Pop(&data);
        std::cout<<"消费者执行的task result-> "<<data()<<std::endl;
    }
}
int main()
{
    srand(time(nullptr) ^ 1314);
    RingQueue<DataType>* loopQueue = new RingQueue<DataType>();
    pthread_t p1,p2,c1,c2;
    pthread_create(&p1,nullptr,ProdRunFunc,loopQueue);
    pthread_create(&p2,nullptr,ProdRunFunc,loopQueue);
    pthread_create(&c1,nullptr,ConRunFunc,loopQueue);
    pthread_create(&c2,nullptr,ConRunFunc,loopQueue);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    return 0;
}